module Fastlane
  module Actions
    module SharedValues
      DELETE_TAG_CUSTOM_VALUE = :DELETE_TAG_CUSTOM_VALUE
    end

    class DeleteTagAction < Action
      def self.run(params)
      
          # 获取传入参数
          tagName = params[:tag]
          isDeleteLocalTag = params[:rl]
          isDeleteRemoteTag = params[:rr]
          
          # 1. 定义数组
          cmds = []
          
          # 2. 存放指令
          if isDeleteLocalTag
            # 删除本地tag
            cmds << "git tag -d #{tagName}"
          end
    
          if isDeleteRemoteTag
            # 删除远程tag
            cmds << "git push origin :#{tagName}"
          end
  
          # 拼接指令
          cmd = cmds.join('&')
          
          # 执行指令，指令必须为字符串
          Actions.sh(cmd)
      end

      #####################################################
      # @!group Documentation
      #####################################################

      def self.description
        ""
      end

      def self.details
        # Optional:
        # this is your chance to provide a more detailed description of this action
        "可以删除tag"
      end

      def self.available_options
        # Define all options your action supports. 
        
        # Below a few examples
        [
FastlaneCore::ConfigItem.new(key: :tag,
                             description: "需要删除的tag名称",
                             is_string: true,
                             optional: false),
FastlaneCore::ConfigItem.new(key: :rl,
                             description: "是否需要删除的本地tag",
                             is_string: false,
                             optional: false,
                             default_value: true),
FastlaneCore::ConfigItem.new(key: :rr,
                             description: "是否需要删除的远程tag",
                             is_string: false,
                             optional: false,
                             default_value: true)
        ]
      end

      def self.output
        # Define the shared values you are going to provide
        # Example
      end

      def self.return_value
        # If your method provides a return value, you can describe here what it does
        nil
      end

      def self.authors
        # So no one will ever forget your contribution to fastlane :) You are awesome btw!
        ["Guorui"]
      end

      def self.is_supported?(platform)
        # you can do things like
        # 
        #  true
        # 
        #  platform == :ios
        # 
        #  [:ios, :mac].include?(platform)
        # 

        platform == :ios
      end
    end
  end
end
